$(function () {
    var a = sessionStorage.getItem("uid");
    a || (console.error("uid not exist"), location.hash = "login"),
        $.get(hostUrl + "/customer/info",
            function (t) {
                !0 === t.meta.success ? ($("#card-no").text(t.data.bank_card_code),
                 $("#balance").text(o(yts.branchToYuan(t.data.balance)) + " 元"), 
                 $("#balanceValue").val(yts.branchToYuan(t.data.balance)), 
                 $("#withdraw-title").text("当前最大可出金：" + o(yts.branchToYuan(t.data.balance)) + " 元")) : $.toptip(t.meta.message, "error")
            });
    var e = function () {
        var t = $("#cap-his-field"),
            e = $("#withdraw-field"),
            i = $("#deposit-field");
        t.css("display", "block"),
            e.css("display", "none"),
            i.css("display", "none");
        var o = $("#cap-his"),
            l = $("#withdraw"),
            n = $("#deposit");
        o.addClass("text-color"),
            l.removeClass("text-color"),
            n.removeClass("text-color");
        var r = "";
        var changeType = {
            CASH_IN: "充值",
            CASH_OUT: "提现",
            LOCK: "冻结",
            UNLOCK: "解冻",
            SERVICE_FEE: "服务费",
            TRADE_WIN: "交易盈亏",
            BROKERAGE: "佣金",
            ADJUST: "后台调整",
            TUIHUI: "退汇",
            PURCHASE: "购买商品",
            PURCHASE_CANCEL: "取消商品订单",
            MOVE: "后台转移",
            ORDER_BUY:"交易买入"
        }
        $.get(hostUrl + "/pay/capital-history-m",
            function (t) {
                if (!0 === t.meta.success) {
                    t.data = t.data.content;
                    for (var a = 0; a < t.data.length; a++) {
                        var e = t.data[a];

                        r += '               <div class="weui-flex capital_item">\n' +
                            '                    <div class="weui-flex__item">' + e.created_at + '</div>\n' +
                            '                    <div class="weui-flex__item">' + e.comment + '</div>\n' +
                            '                    <div class="weui-flex__item">' + yts.branchToYuan(e.asset_change) + '</div>\n' +
                            '                    <div class="weui-flex__item">' + s(yts.branchToYuan(e.asset_after)) + '</div>\n' +
                            '                </div>\n'
                    }
                    $("#capital-history").html(r)
                } else $.toptip(t.meta.message, "error")
            })
    };
    e(),
        $("#deposit").on("click",
            function () {
                !
                    function () {
                        var t = $("#withdraw-field"),
                            a = $("#deposit-field"),
                            e = $("#cap-his-field");
                        a.css("display", "block"),
                            t.css("display", "none"),
                            e.css("display", "none");
                        var s = $("#cap-his"),
                            i = $("#withdraw"),
                            o = $("#deposit");
                        s.removeClass("text-color"),
                            i.removeClass("text-color"),
                            o.addClass("text-color")
                    }()
            }),
        $("#withdraw").on("click",
            function () {
                var t = $("#withdraw-field"),
                    a = $("#deposit-field"),
                    e = $("#cap-his-field");
                t.css("display", "block"),
                    a.css("display", "none"),
                    e.css("display", "none");
                var s = $("#withdraw"),
                    i = $("#cap-his"),
                    o = $("#deposit");
                i.removeClass("text-color"),
                    s.addClass("text-color"),
                    o.removeClass("text-color")
            }),
        $("#cap-his").on("click",
            function () {
                e()
            });
    var s = function (a) {
        var e = (a = parseFloat((a + "").replace(/[^\d\.-]/g, "")).toFixed(2) + "").split(".")[0].split("").reverse(),
            s = a.split(".")[1];
        for (t = "", i = 0; i < e.length; i++) t += e[i] + ((i + 1) % 3 == 0 && i + 1 != e.length ? "," : "");
        return t.split("").reverse().join("") + "." + s
    },
        o = function (t) {
            return s((parseInt(100 * t) / 100).toFixed(2))
        };
    $("#submit-withdraw").on("click",
        function () {
            var t = $("#withdraw-amt").val(),
                e = $("#pay-password").val();
            t && !isNaN(t) ? parseFloat(t) < 100 ? $.toptip("请输入100元以上提现金额") : parseFloat(t) > parseFloat($("#balanceValue").val()) ? $.toptip("提现金额不能大于账户余额") : e ? e.length < 6 ? $.toptip("支付密码小于6位") : $.ajax({
                method: "post",
                url: hostUrl + "/pay/withdraw",
                contentType: "application/json; charset=utf-8",
                data: '{\n    "uid" : "' + a + '"    ,"trans_amt" : "' + parseFloat(t).toFixed(0) + '"    ,"password" : "' + e + '"}',
                success: function (t) {
                    !0 === t.meta.success ? ($.toptip("提现成功", "success"), $("#balance").text(o(t.data) + " 元"), $("#withdraw-title").text("当前最大可出金：" + o(t.data) + " 元"), $("#withdraw-amt").val(""), $("#pay-password").val("")) : $.toptip(t.meta.message)
                }
            }) : $.toptip("请输入支付密码") : $.toptip("请输入提现金额")
        }),
        $("#returnLink").on("click",
            function () {
                vipspa.setMessage({
                    id: "person_info",
                    content: {
                        tab: "uInfo"
                    }
                }),
                    location.hash = "trade"
            })
});